import os
import time
import unittest
from library.HTMLTestRunnerNew import HTMLTestRunner
from config import REPORTDIR,CASEDIR
import pytest

class Test_run(object):

    def __init__(self):
        self.suit = unittest.TestSuite()
        self.load = unittest.TestLoader()
        self.suit.addTest(self.load.discover(CASEDIR))
        self.runner = HTMLTestRunner(
            stream=open(os.path.join(REPORTDIR, 'report.html'), 'wb'),
            title='【小郁】UI自动化测试',
            description='我们是专业的',
            tester='AUTO-TESTER'
        )

    def excute(self):
        self.runner.run(self.suit)





if __name__=="__main__":
    test_run = Test_run()
    test_run.excute()





#
# date = str(int(time.time()))
# # 测试数据
# # testcases= os.path.join(os.path.dirname(os.path.dirname((os.path.abspath(__file__)))), "testcases")
# testcases = r"D:\Python36\webAuto\testcases"
# # 测试报告
# # report_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "report")
# report_path = r"D:\Python36\webAuto\report"
# # report_name = date + '.html'
# report_file = os.path.join(report_path, date + "report.html")
#
# suite = unittest.TestSuite()
# loader = unittest.TestLoader()
# suite.addTest(loader.discover(testcases))
# runner = HTMLTestRunner(stream=open(report_file, "wb"),
#                         title="课堂派test",
#                         description=date + '课堂派test',
#                         tester='小郁')
# runner.run(suite)

#
# if __name__ == '__main__':
#     pytest.main(['-m success','--html=report.html'])
#     # pytest.main(['-m login','--html={}'.format(os.path.join(report_path,report_name))])
#
